#!/bin/sh
# 安装PHP Redis扩展
App=redis
AppName="PHP Redis扩展"
AppSrcBase=/App/src
AppSrcDir=$(find $AppSrcBase -maxdepth 1 -name phpredis -type d | sed -e 's/^.\///')

export PATH=/App/php/bin:$PATH
ExtensionDir=$(php-config --extension-dir)

# 安装
finstall() 
{
    ls $ExtensionDir/$App.so &> /dev/null && echo "$AppName 已安装" || fupdate
}

# 更新
fupdate() 
{
    cd $AppSrcBase
    [ -z "$AppSrcDir" ] && git clone git://github.com/nicolasff/phpredis.git
    AppSrcDir=$(find $AppSrcBase -maxdepth 1 -name phpredis -type d | sed -e 's/^.\///')

    cd $AppSrcDir
    phpize && ./configure && make && make install

    [ $? -eq 0 ] && echo "$AppName 安装成功" || echo "$AppName 安装失败"
}

ScriptFile=$(basename $0)
case "$1" in
    "install") finstall;;
    "update" ) fupdate;;
    * )
    echo "用法: $ScriptFile {install|update}"
    ;;
esac
